package com.btkjgc.service.impl;

import com.btkjgc.models.DictionaryT;
import com.btkjgc.service.intf.DictionaryService_Intf;
import com.btkjgc.utils.HibernateUtil;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created by HelloWorld on 2015/4/21.
 */
@Service
public class DictionaryService_Impl implements DictionaryService_Intf
{
	@SuppressWarnings("unchecked")
	@Override
	public HashMap<Integer, String> getDictoinaryByName(int entityid,
			String name)
	{
		String hql = "from DictionaryT where entityid = ? and name = ?";
		String para[] = { Integer.toString(entityid), name };
		List<DictionaryT> dictionaryTList = (List<DictionaryT>) HibernateUtil
				.executeQuery(hql, para);
		HashMap<Integer, String> map = new HashMap<Integer, String>();
		for (DictionaryT dictionaryT : dictionaryTList)
		{
			map.put(dictionaryT.getKey(), dictionaryT.getValue());
		}
		return map;

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<String> getDictoinaryValuesByName(int entityid, String name)
	{
		String hql = "select value from DictionaryT where entityid = ? and name = ?";
		String para[] = { Integer.toString(entityid), name };
		return (List<String>) HibernateUtil.executeQuery(hql, para);
	}

	@Override
	public Integer getDictoinaryKeyByName(String value, int entityid,
			String name)
	{
		String hql = "select key from DictionaryT where entityid = ? and name = ? and value = ?";
		String para[] = { Integer.toString(entityid), name, value };
		Object obj = HibernateUtil.objectQuery(hql, para);
		return (Integer) obj;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DictionaryT> getDictionaryByName(String name, int entityid)
	{
		String hql = "from DictionaryT where entityid = ? and name = ?";
		String[] param = { String.valueOf(entityid), name };
		return HibernateUtil.executeQuery(hql, param);
	}
}
